package self.learn.record.proxy.cglib;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;
import self.learn.record.proxy.static_.Family;
import self.learn.record.proxy.static_.ZhangFamily;

import java.lang.reflect.Method;

/**
 * @author Mercy Yang
 */
public class MatchmakerCglibProxy implements MethodInterceptor {

    public <T> T getProxy(){
        Enhancer enhancer = new Enhancer();

        enhancer.setSuperclass(ZhangFamily.class);
        enhancer.setCallback(this);

        return (T)enhancer.create();
    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {
        Object result = methodProxy.invokeSuper(o,objects);
        return result;
    }
}
